<template>
  <ma-crud ref="crudRef" :columns="columns" :options="crud">
    <template #search-postName="{ searchForm, component }">
      <a-input
        v-model.trim="searchForm[component.dataIndex]"
        :style="{ width: '240px' }"
        allow-clear
        placeholder="请输入职务名称"
      >
        <template #prefix>
          <icon-search />
        </template>
      </a-input>
    </template>
    <template #search-postCode="{ searchForm, component }">
      <a-input
        v-model.trim="searchForm[component.dataIndex]"
        :style="{ width: '240px' }"
        allow-clear
        placeholder="请输入职务编码"
      >
        <template #prefix>
          <icon-search />
        </template>
      </a-input>
    </template>
  </ma-crud>
</template>
<script lang="ts" name="Post" setup>
import { addPost, delPost, listPost, updatePost } from "@/api/system/post";

const crud = reactive({
  id: "postId",
  pk: "postId",
  title: "职务查询",
  formLayout: "vertical",
  formOption: {
    width: 600,
    layout: [
      {
        formType: "grid",
        gutter: 16,
        cols: [
          { span: 12, formList: [{ dataIndex: "postName" }] },
          { span: 12, formList: [{ dataIndex: "postCode" }] },
          { span: 12, formList: [{ dataIndex: "remark" }] },
          { span: 12, formList: [{ dataIndex: "postStatus" }] }
        ]
      }
    ]
  },
  api: listPost,
  showIndex: true,
  operationColumn: true,
  operationColumnAlign: "center",
  operationColumnWidth: 200,
  pageLayout: "normal",
  requestParams: { orderBy: "createTime", orderType: "desc" },
  add: { api: addPost, auth: ["system:post:add"], text: "新增", show: true },
  delete: { api: delPost, auth: ["system:post:delete"], text: "删除", show: true },
  edit: { api: updatePost, auth: ["system:post:edit"], text: "编辑", show: true }
});

const columns = reactive([
  {
    title: "职务编号",
    dataIndex: "postId",
    slotName: "index",
    align: "center",
    hide: true
  },
  {
    title: "职务名称",
    dataIndex: "postName",
    search: true,
    align: "center",
    commonRules: {
      required: true,
      message: "请输入职务名称"
    }
  },
  {
    title: "职务编码",
    dataIndex: "postCode",
    search: true,
    align: "center",
    commonRules: {
      required: true,
      message: "请输入职务编码"
    }
  },
  {
    title: "描述",
    dataIndex: "remark",
    align: "center",
    formType: "textarea",
    autoSize: { minRows: 3, maxRows: 6 },
    maxLength: 200,
    showWordLimit: true,
    hide: true
  },
  {
    title: "职务状态",
    dataIndex: "postStatus",
    formType: "radio",
    align: "center",
    dict: {
      name: "sys_normal_disable",
      cache: true,
      props: { label: "dictLabel", value: "dictValue" },
      translation: true,
      tagColors: true
    },
    addDefaultValue: 0
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    align: "center",
    addDisplay: false,
    editDisplay: false
  }
]);
</script>
